package com.zky.basic.service.impl;

import com.zky.basic.mapper.BaseMapper;
import com.zky.basic.query.BaseQuery;
import com.zky.basic.service.BaseService;

import com.zky.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 业务实现类：员工
 */

@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void add(T t) {
        baseMapper.add(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public PageList<T> pageQuery(BaseQuery baseQuery) {
        Integer integer = baseMapper.queryCount(baseQuery);
        if(integer < 1){
            return new PageList<>();
        }

        List<T> ts = baseMapper.queryData(baseQuery);

        return new PageList<T>(ts,integer);
    }

    @Override
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }


}
